package com.jack.thinking.thread.core._1;

/**
 * 
 * @author wangbingwu
 *
 */
public class SuspendMonopolyObject {
	public static void main(String[] args) throws Exception {
		SynObject syn = new SynObject();
		Thread t1 = new Thread() {
			@Override
			public void run() {
				syn.printString();
			}
		};
		t1.setName("A");
		t1.start();
		Thread.sleep(1000L);
		Thread t2 = new Thread() {
			@Override
			public void run() {
				System.out.println("enter t2 ----");
				syn.printString();
			}
		};
		t2.start();
	}
}

class SynObject{
	
	@SuppressWarnings("deprecation")
	synchronized public void printString() {
		System.out.println("entering synObject inner----" + Thread.currentThread().getName());
		if(Thread.currentThread().getName().equals("A")) {
			Thread.currentThread().suspend();
		}
		System.out.println("outering synObject inner----" + Thread.currentThread().getName());
	}
}
